/*
 * SmajlikButton.java
 *
 * Created on 26.11.2007, 19:08:17
 *
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cz.possoft.client.gui.panel.chatpanel.components;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JTextField;

/**
 *
 * @author mara
 * 
 * trida predstavuje jeden button se smajlikem
 */
public class SmajlikButton extends JButton {

    // cislo smajlika (0...6)
    private int id;
    // ikona smajlika
    private ImageIcon icon;
    // pole do ktereho se zapisuje pri stisku smajlika
    private JTextField vstup;

    SmajlikButton(int id, ImageIcon icon, JTextField vstup) {
        super(icon);
        setPreferredSize(new Dimension(24, 24));
        this.id = id;
        this.icon = icon;
        this.vstup = vstup;        
        this.addActionListener(new SmajlikListener());
    }    

    public int getId() {
        return id;
    }

    public ImageIcon getMyIcon() {
        return icon;
    }
    
    class SmajlikListener implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            vstup.setText(vstup.getText() + "*" + String.valueOf(id) + "*");
            vstup.grabFocus();
        }
    }    
}
